package tests;

import game.Board;
import game.GridLockState;
import game.Piece;
import game.PieceBlue;
import gps.api.GPSState;
import gps.exception.NotAppliableException;

import java.awt.Point;
import java.util.ArrayList;
import java.util.List;

import junit.framework.Assert;

import org.junit.Test;

import rules.MoveRight;

public class PiecesMovements {
	
	/*CURRENT  
	  |  0  |  |  0  |  |  0  |  |  1  |  |  1  |  |  2  |
	  |  3  |  |  0  |  |  0  |  |  0  |  |  0  |  |  2  |
	  |  3  |  |  -1  |  |  -1  |  |  -1  |  |  -1  |  |  2  |
	  |  3  |  |  0  |  |  0  |  |  4  |  |  0  |  |  0  |
	  |  5  |  |  6  |  |  6  |  |  4  |  |  0  |  |  0  |
	  |  5  |  |  0  |  |  0  |  |  4  |  |  0  |  |  0  |*/

	private static List<Piece> usePieces1() {
		List<Piece> pieces = new ArrayList<Piece>();
//		pieces.add(new Piece(1, new Point(3, 0), 2, false));
		pieces.add(new Piece(2, new Point(5, 1), 3, true));
//		pieces.add(new Piece(3, new Point(0, 1), 3, true));
//		pieces.add(new Piece(4, new Point(3, 3), 3, true));
//		pieces.add(new Piece(5, new Point(0, 4), 2, true));
//		pieces.add(new Piece(6, new Point(1, 4), 2, false));

		return pieces;
	}

	/*CURRENT
  |  0  |  |  0  |  |  1  |  |  1  |  |  0  |  |  0  |
  |  3  |  |  0  |  |  0  |  |  0  |  |  0  |  |  0  |
  |  3  |  |  -1  |  |  -1  |  |  0  |  |  0  |  |  0  |
  |  3  |  |  0  |  |  0  |  |  4  |  |  0  |  |  2  |
  |  5  |  |  6  |  |  6  |  |  4  |  |  0  |  |  2  |
  |  5  |  |  0  |  |  0  |  |  4  |  |  0  |  |  2  |*/
	
	private static List<Piece> usePieces2() {
		List<Piece> pieces = new ArrayList<Piece>();
		pieces.add(new Piece(3, new Point(0, 1), 3, true));
		pieces.add(new Piece(5, new Point(0, 4), 2, true));
		pieces.add(new Piece(6, new Point(1, 4), 2, false));
		pieces.add(new Piece(4, new Point(3, 3), 3, true));
		pieces.add(new Piece(2, new Point(5, 3), 3, true));
		pieces.add(new Piece(1, new Point(2, 0), 2, false));
		
		return pieces;
	}
	
	private final PieceBlue blue1 = new PieceBlue(-1, new Point(1, 2), 2, false);
	private final int width = 6;
	private final int height = 6;
	private final Point exit = new Point(5,2);
	
	private List<Piece> pieces1 = usePieces1();
	private Board board1 = new Board(width, height, exit, blue1, pieces1);
	
	private GPSState state1 = new GridLockState(board1);
	
	
	private List<Piece> pieces2 = usePieces2();
	private Board board2 = new Board(width, height, exit, blue1, pieces2);
	
	@Test
	public void MoveRightTimes1Piece1Board1(){
		System.out.println("\nTest MoveRightTimes1Piece1Board1");
		Board newBoard;
		System.out.println("BEFORE");
		System.out.println(board1);
		System.out.println();
		System.out.println("AFTER");
		System.out.println(newBoard = board1.movePiece(pieces1.get(0), new Point(4,0)));
		Assert.assertTrue(newBoard == null);
	}
	
	@Test
	public void MoveRightTimes1Piece1Board1State1(){
		System.out.println("\nTest MoveRightTimes1Piece1Board1State1");
		System.out.println("BEFORE");
		System.out.println(board1);
		System.out.println();
		MoveRight rule = new MoveRight(pieces1.get(0), 1);
		GPSState newState = null;
		try {
			newState = rule.evalRule(state1);
			System.out.println("AFTER");
			System.out.println(newState);
		} catch (NotAppliableException e) {
		}
		Assert.assertTrue(newState == null);
	}
	
	@Test
	public void MoveDownTimes2Piece4Board2(){
		System.out.println("\nMoveDownTimes2Piece4Board2");
		Board newBoard;
		System.out.println("BEFORE");
		System.out.println(board2);
		System.out.println();
		System.out.println("AFTER");
		System.out.println(newBoard = board2.movePiece(pieces2.get(3), new Point(3,5)));
		Assert.assertTrue(newBoard == null);
	}
	
	
	@Test
	public void PointHash(){
		Point point1 = new Point(1,2);
		Point point2 = new Point(2,1);
		Assert.assertFalse(point1.equals(point2));
	}
	
	@Test
	public void PieceHash(){
		Point point1 = new Point(1,2);
		Point point2 = new Point(2,1);
		Assert.assertFalse(point1.equals(point2));
	}
	
	@Test
	public void MovePiece(){
		System.out.println("\nMoveDownTimes3Piece2");
		Board newBoard;
		System.out.println("BEFORE");
		System.out.println(board1);
		System.out.println();
		System.out.println("AFTER");
		System.out.println(newBoard = board1.movePiece(pieces1.get(0), new Point(5,4)));
		Assert.assertTrue(newBoard != null);
	}
}
